package com.ld.wms.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

    public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static final String YYYYMMDDHHMMSS2 = "yyyy/MM/dd/ HH:mm:ss";
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String YYYY_MM_DD_HH_MM_SS2 = "yyyy年MM月dd日HH时mm分ss秒";

    public static Long currentTimeMillis() {
        return System.currentTimeMillis();
    }

    /**
     * 将日期转换成指定日期格式
     *
     * @param date
     * @param pattern
     * @return
     */
    public static String dateToStr(Date date, String pattern) {
        if (pattern == null) {
            pattern = YYYY_MM_DD_HH_MM_SS;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
        String formatDateStr = dateFormat.format(date);
        return formatDateStr;
    }

    /**
     * 给某个时间加多少秒
     * @param date
     * @param second
     * @return
     */
    public static Date dateAddSecond(Date date, Long second) {
        second = second * 1000;
        date.setTime(date.getTime() + second);
        return date;
    }

    public static Date dataAddDay(Date date, Integer day) {
        // 创建一个Calendar实例
        Calendar calendar = Calendar.getInstance();
        // 设置calendar的时间为当前时间
        calendar.setTime(date); // 或者使用calendar.setTimeInMillis(System.currentTimeMillis());
        // 添加几天
        calendar.add(Calendar.DATE, day);
        // 获取修改后的日期
        Date dateAfterAddingDays = calendar.getTime();
        return dateAfterAddingDays;
    }
}
